package com.shioirikukuri.mapper;

import com.shioirikukuri.entity.Gift;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GiftMapper {

	@Insert("INSERT INTO gifts(name, description, required_points, stock_quantity, is_listed) " +
			"VALUES(#{name}, #{description}, #{requiredPoints}, #{stockQuantity}, #{isListed})")
	@Options(useGeneratedKeys = true, keyProperty = "id")
	void insert(Gift gift);

	@Select("SELECT * FROM gifts WHERE id = #{id}")
	Gift findById(Long id);

	@Select("SELECT * FROM gifts")
	List<Gift> findAll();

	@Update("UPDATE gifts SET name=#{name}, description=#{description}, required_points=#{requiredPoints}, " +
			"stock_quantity=#{stockQuantity}, is_listed=#{isListed} WHERE id=#{id}")
	void update(Gift gift);

	@Delete("DELETE FROM gifts WHERE id = #{id}")
	void deleteById(Long id);
}